#include<string>
#include<unordered_set>

using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if (s.size() == 1)
            return 1;
        unordered_set<char> set;
        int left = 0;
        int right = 0;
        int len = 0;
        while (right < s.size())
        {
            if (set.count(s[right]) == 0)
            {
                set.insert(s[right]);
                right++;
            }
            else
            {
                len = len > set.size() ? len : set.size();
                while (s[left] != s[right])
                {
                    set.erase(s[left]);
                    left++;
                }
                set.erase(s[left]);
                left++;
            }
        }
        len = len > set.size() ? len : set.size();
        return len;
    }
};

int main()
{
    Solution s;
    s.lengthOfLongestSubstring("abcabcbb");
    return 0;
}